import 'package:api/pages/provider/getX/demo/shop/shop_controller.dart';
import 'package:api/pages/provider/getX/demo/shop/shop_model.dart';
import 'package:api/pages/provider/getX/demo/shop/show_item_widget.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class ShopItemPage extends StatefulWidget {
  final ShopClassBean element;
  ShopItemPage(this.element);
  @override
  _ShopItemPageState createState() => _ShopItemPageState();
}

class _ShopItemPageState extends State<ShopItemPage> {
// 注入ShopController
  ShopController _shopController = Get.put(ShopController());
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // 请求商品列表
    _shopController.requesShopGoodsList(widget.element);
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        id: "${widget.element.id}",
        builder: (ShopController controller) {
          List<GoodsBean> list = controller.currentGoods;
          return ListView.builder(
            itemCount: list.length,
            itemBuilder: (BuildContext context, int index) {
              GoodsBean goodsBean = list[index];
              return ShopItemWidget(goodsBean);
            },
          );
        });
  }
}
